--
-- @Author:      name
-- @DateTime:    2018-03-30 23:05:48
-- @Description: 消息的处理

local skynet = require "skynet"
local log = require "Log"


local Command = class("Command")

---------------------------------------------------------
-- Private
---------------------------------------------------------
function Command:ctor(message)
	self.msg = message	
	self.tbService = {}

	self:register()
		
end

--注册本服务里的消息
function Command:register()
	self.msg:registerSelf('add_robot',handler(self,self.addRobot))
	self.msg:registerSelf('del_robot',handler(self,self.delRobot))
	--
end

function Command:addRobot(data,user)
	print("____addRobot_____zhajinhua__",data)
	local playerid = data.mid
	if self.tbService[playerid] then 
		self:delRobot(data)
		--return
	end
	local service = skynet.newservice('zhajinghua_service')
	skynet.call(service, 'lua', 'start', data, user)	
	self.tbService[playerid] = service
end

function Command:delRobot(data)
	print("____delRobot_____zhajinhua__",data)
	local playerid = data.mid
	local service = self.tbService[playerid]
	if service then
		skynet.send(service, 'lua', 'exit')
		self.tbService[playerid] = nil
	end
end


return Command